import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_module/global/colors.dart';
import 'package:flutter_module/pages/homePage/views/MusicTab.dart';
import 'package:flutter_module/pages/homePage/views/PicTab.dart';
import 'package:flutter_module/pages/homePage/views/RecommendTab.dart';
import 'package:flutter_module/pages/homePage/views/VideoTab.dart';
import 'package:flutter_module/utils/jh_login_textfield.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(

        //appBar: AppBar(
        //  backgroundColor: Colors.black26,
        //  title: Text('container'),
        //),
        body: HomePage(),
      ),
    );
  }
}
class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool _display=false;
  final List<Widget> _tabs = [
    Tab(text: "推荐"),
    Tab(text: "音频"),
    Tab(text: "数字藏品"),
    Tab(text: "视频"),
    Tab(text: "文档"),
  ];
  final List<Widget> _tabViews = [
    RecommendTab(),
    MusicTab(),
    PicTab(),
    VideoTab(),
    MusicTab(),
  ];
  @override
  void initState() {
    super.initState();
    _loadData();
  }

  void _loadData() async {
    EasyLoading.show(
      status: "Loading...",
      //duration: Duration(seconds: 2)
      //maskType: EasyLoadingMaskType.black,
    );
    await Future.delayed(Duration(milliseconds: 1000), () async {
      EasyLoading.dismiss();
      setState(() {
        _display=true;
      });
    });

  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(
      BoxConstraints(
          maxWidth: MediaQuery.of(context).size.width,
          maxHeight: MediaQuery.of(context).size.height),
      designSize: Size(476, 922),
    );

    if(_display==true) {
      return Scaffold(
        appBar: _appBar(),
        backgroundColor: Color(0xff000B1F),
        body: Container(
          color: Color(0xff000B1F),
          child: DefaultTabController(
            length: _tabs.length,
            child: Scaffold(
              backgroundColor: Color(0xff000B1F),
              appBar: _tabBar(),
              body: TabBarView(
                children: _tabViews,
              ),
            ),
          ),
        ),
      );
    }else{
      return Container(
        width: 0,
        height: 0,
        color: AppColors.background,
      );
    }

  }

  Widget _appBar() {
    return PreferredSize(
      preferredSize: Size.fromHeight(ScreenUtil().setHeight(58)),
      child: AppBar(
        backgroundColor: Color(0xff000B1F),
        titleSpacing: 15,
        elevation: 0,
        automaticallyImplyLeading: false,
        //隐藏返回箭头
        title: Row(
          children: [
            // Image.asset(
            //   'assets/img/icon.png',
            //   width: ScreenUtil().setHeight(35),
            //   height: ScreenUtil().setHeight(35),
            //   fit: BoxFit.cover,
            // ),
            Text(
              '艺数云',
              style: TextStyle(
                fontSize: ScreenUtil().setSp(25),
                color: AppColors.primary,
              ),
            ),
            SizedBox(
              width: ScreenUtil().setWidth(20),
            ),
            Container(
              width: ScreenUtil().setWidth(326),
              child: Container(
                decoration: new BoxDecoration(
                  color: Color(0xffF1F2F2),
                  borderRadius: BorderRadius.all(
                    Radius.circular(25.0),
                  ),
                ),
                alignment: Alignment.center,
                height: ScreenUtil().setHeight(40),
                child: JhLoginTextField(
                  border: InputBorder.none,
                  leftWidget: InkWell(
                    child: Container(
                        padding: EdgeInsets.all(8),
                        child: Icon(
                          Icons.search,
                          color: AppColors.subtext,
                        )),
                    onTap: () {},
                  ),
                  hintText: 'nft',
                  isShowDeleteBtn: true,
                  isDense: false,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _tabBar() {
    return TabBar(
      tabs: _tabs,
      labelColor: AppColors.primary,
      labelStyle: TextStyle(
          fontWeight: FontWeight.bold,
          fontSize: ScreenUtil().setSp(25),
          fontFamily: '方正御墨行书'),
      unselectedLabelColor: Colors.white,
      unselectedLabelStyle:
      TextStyle(fontSize: ScreenUtil().setSp(18), fontFamily: '方正御墨行书'),
      indicatorSize: TabBarIndicatorSize.tab,
      indicatorColor: AppColors.primary,
      indicatorWeight: 4,
      isScrollable: true,
    );
  }


}
